05. P Controller Solution

def run(robot, tau, n=100, speed=1.0):
    x_trajectory = []
    y_trajectory = []
    for i in range(n):
        cte = robot.y
        steer = -tau * cte
        robot.move(steer, speed)
        x_trajectory.append(robot.x)
        y_trajectory.append(robot.y)
    return x_trajectory, y_trajectory

The cross track error, cte is the current y position of the robot (our reference is a horizontal line) along the x-axis. To get the steering value we multiply the tau parameter with the cte. We then call the move method which causes the robot to move based on the steer and speed values. Add the x and y coordinates to the respective lists and then return them at the end.

Implement P Controller Solution - Artificial Intelligence for Robotics